unit EscolherPagamento;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, jpeg, Grids, DBGrids, StdCtrls, Mask, DBCtrls, DB, DBClient,
  Buttons;

type
  TfrmEscolherPagamento = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    btnCancelar: TBitBtn;
    btnAdicionarFormas: TBitBtn;
    listFormas: TListBox;
    dsformasPag: TDataSource;
    ListBox2: TListBox;
    DSFormas: TDataSource;
    edtValorPago: TEdit;
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure btnAdicionarFormasClick(Sender: TObject);
    procedure edtValorPagoExit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmEscolherPagamento: TfrmEscolherPagamento;
implementation

uses menu, DMCaixa, Funcoes, cupomA, MaskUtils;

{$R *.dfm}

procedure TfrmEscolherPagamento.FormActivate(Sender: TObject);
begin
  dsformasPag.DataSet.Close;
  dsformasPag.DataSet.Open;
  listFormas.Clear;
  while not dsformasPag.DataSet.Eof do
  begin
    listFormas.Items.Add(dsformasPag.DataSet.FieldByName('TIPOBASICO').AsString + ' - ' +  dsformasPag.DataSet.FieldByName('DESCFORMAPAG').AsString );
    dsformasPag.DataSet.Next;
  end;
end;

procedure TfrmEscolherPagamento.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  DSFormas.DataSet.Close;
  if (dsformasPag.State in [dsEdit, dsInsert]) then
     dsformasPag.DataSet.Close;
   Action := cafree;
end;

procedure TfrmEscolherPagamento.FormKeyPress(Sender: TObject;
  var Key: Char);
begin
 if key=#13 then
    begin
      key:=#0;
      perform(WM_NextDLGCtl,0,0);
    end;
end;

procedure TfrmEscolherPagamento.btnAdicionarFormasClick(Sender: TObject);
begin
  if not (DSFormas.State = dsinsert)
     then DSFormas.DataSet.Append;
  with DSFormas.DataSet do
    begin
    FieldByName('Documento').AsString   :=  NroCupom ;
    FieldByName('DataSaida').AsDateTime := Date();
    FieldByName('CodLoja').AsInteger    := 1;
    FieldByName('Cliche').AsInteger     := 1;
//    FieldByName('CodFormaPag').AsInteger:= codFormPagamento;
    showmessage('valor' + edtValorPago.Text);
    FieldByName('Valor').AsString := edtValorPago.Text;
    Edit;
    Post;
   (DSFormas.DataSet as TClientDataSet).ApplyUpdates(0);
  end;
end;

procedure TfrmEscolherPagamento.edtValorPagoExit(Sender: TObject);
var i : integer;
begin
 edtValorPago.Text :=  FormatarReal(StrtoFloat(edtValorPago.Text));
end;


end.
